package com.example.palette.start;


import android.os.Process;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;

public abstract class AndroidStartTask<T> implements IStartTask<T> {

    private CountDownLatch countDownLatch = new CountDownLatch(getDependenciesCount());
    @Override
    public List<Class<? extends IStartTask<?>>> dependencies() {
        return null;
    }

    @Override
    public int getDependenciesCount() {
        List<Class<? extends IStartTask<?>>> dependencies = dependencies();
        return dependencies == null ? 0 : dependencies.size();
    }

    @Override
    public void toWait() {
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void toNotify() {
        countDownLatch.countDown();
    }

    @Override
    public Executor executor() {
        return StartTaskExecutors.ioExecutor;
    }

    @Override
    public int priority() {
        return Process.THREAD_PRIORITY_DEFAULT;
    }

    @Override
    public boolean inMainThread() {
        return false;
    }

    @Override
    public boolean mainThreadWait() {
        return false;
    }
}
